<template>
  <div class="gl_heightFull gl_contentBox">
    <el-button type="success" size="mini" style="margin-bottom:15px" @click="openMemberfee()">新增会员缴费</el-button>
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :md="4" :lg="4">
          <p>名称</p>
          <el-input v-model="Api_GET_ClubFeeRequestQO.Filter" placeholder="请输入名称" size="mini" clearable @change="gettablelist()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <p>提交状态</p>
          <el-select v-model="IsEnabled" size="mini" @change="gettablelist()">
            <el-option label="全部" value="" />
            <el-option v-for="item in dict.feeRequestStatus" :key="item.code" :label="item.value" :value="item.code" />
          </el-select>
        </el-col>
        <el-col :span="6">
          <p>提交时间</p>
          <el-date-picker
            v-model="freeDate"
            size="mini"
            style="width: 100%"
            type="daterange"
            range-separator="至"
            start-placeholder="提交开始日期"
            end-placeholder="提交结束日期"
            value-format="yyyy-MM-dd"
            @change="changeAttendance"
          />
        </el-col>
        <el-col :md="4" :lg="4">
          <el-button type="primary" style="margin-top:25px" size="mini" @click="gettablelist()">筛选</el-button>
          <el-button type="warning" size="mini" @click="reset()">{{ $t('button.Reset') }}</el-button>
        </el-col>
      </el-row>
    </div>

    <div style="margin-top:15px">
      <el-table v-loading="tableLoading" class="gl_table_noBorder" size="mini" :data="tableData">
        <el-table-column label="序号" type="index" align="center" width="55" />
        <el-table-column label="名称" prop="name" />
        <el-table-column label="提交时间">
          <template slot-scope="{ row }">
            <span v-if="row.lastModificationTime">
              {{ row.lastModificationTime | FormatDate('yyyy-MM-dd HH:mm:ss') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="提交机构" prop="organizationUnitName" />
        <el-table-column label="提交状态" align="center">
          <template slot-scope="{row}">
            <span v-for="item in dict.feeRequestStatus" :key="item.code">{{ item.code == row.requestStatusCode ? item.value : '' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="220">
          <template slot-scope="{ row }">
            <el-button size="mini" type="text" @click="todetail(row)">人员详情</el-button>
            <el-button size="mini" :disabled="row.requestStatusCode!=='Draft'" type="text" @click="edit(row)">编辑</el-button>
            <el-button size="mini" :disabled="row.requestStatusCode!=='Draft'" type="text" @click="close(row.id)">删除</el-button>
            <el-button size="mini" type="text" @click="Feeresult(row)">审核结果</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubFeeRequestQO.Page"
        :page-size="Api_GET_ClubFeeRequestQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
    <AddMembership ref="AddMembership" />
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import { api_GET_ClubFeeRequest, api_DELETE_ClubFeeRequestId } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubFeeRequestQO } from '@/lib/form/hall/swaggerForm';
import AddMembership from './addMemberfee.vue';
export default {
  components: {
    AddMembership
  },

  data() {
    return {
      tableData: [],
      tableLoading: false,
      IsEnabled: '',
      Isstate: '',
      totalPage: 0,
      freeDate: [],

      Api_GET_ClubFeeRequestQO: new Api_GET_ClubFeeRequestQO() // 缴费申请数据
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      user: state => state.user.currentOU
    })
  },
  created() {
    this.getDict();
    this.gettablelist();
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict', getDictByType: 'dict/getDictByType' }),
    // 获取考试审核列表
    gettablelist(page) {
      this.tableLoading = true;
      // this.Api_GET_ClubFeeRequestQO.IncludeRequestStatus = true; // type: boolean
      // this.Api_GET_ClubFeeRequestQO.IncludeStudents = true; // type: boolean
      // this.Api_GET_ClubFeeRequestQO.IncludeTotalAmount = true; // type: boolean
      // this.Api_GET_ClubFeeRequestQO.OrganizationUnitId = '62d60e97-3832-4f1c-3da5-3a017d1e1d45';
      this.Api_GET_ClubFeeRequestQO.RequestStatusCode = this.IsEnabled;
      this.Api_GET_ClubFeeRequestQO.Sorting = 'creationTime DESC';
      this.Api_GET_ClubFeeRequestQO.Page = page || 1;
      this.Api_GET_ClubFeeRequestQO.SkipCount = (this.Api_GET_ClubFeeRequestQO.Page - 1) * this.Api_GET_ClubFeeRequestQO.MaxResultCount;
      console.log(this.Api_GET_ClubFeeRequestQO);
      api_GET_ClubFeeRequest(this.Api_GET_ClubFeeRequestQO).then(res => {
        console.log(res);
        this.totalPage = res.totalCount;
        this.tableData = res.items;
        this.tableLoading = false;
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 切换考试日期
    changeAttendance (val) {
      const _start = val ? val[0] + ' 00:00:00' : null;
      const _end = val ? val[1] + ' 23:59:59' : null;
      this.Api_GET_ClubFeeRequestQO.MinCreationTime = _start;
      this.Api_GET_ClubFeeRequestQO.MaxCreationTime = _end;

      this.gettablelist();
    },
    // 删除按钮
    close(id) {
      this.$confirm(`您确定要删除吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          api_DELETE_ClubFeeRequestId(id).then(res => {
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.gettablelist();
          }, error => {
            const _msg = error.error.message || error.message;
            this.$message({ type: 'error', message: _msg });
          });
        });
    },
    // 新增会员费缴纳
    openMemberfee() {
      this.$refs.AddMembership.dialogVisible = true;
    },
    // 编辑会员费缴纳
    edit(row) {
      console.log(row);
      this.$refs.AddMembership.id = row.id;
      this.$refs.AddMembership.CreateFeeRequestInput.name = row.name;
      this.$refs.AddMembership.dialogVisible = true;
    },
    // 打开详情
    todetail(row) {
      this.$router.push({ name: 'Feepeople', query: { id: row.id }});
    },
    // 审核结果
    Feeresult(row) {
      this.$router.push({ name: 'Feeresult', query: { id: row.id }});
    },
    // 分页按钮
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubFeeRequestQO.MaxResultCount = MaxResultCount;
      this.gettablelist();
    },
    pageIndexChange(currentPage) {
      this.gettablelist(currentPage);
    },
    // 重置按钮
    reset () {
      this.freeDate = [];
      this.IsEnabled = '';
      this.Api_GET_ClubFeeRequestQO = new Api_GET_ClubFeeRequestQO();
      this.gettablelist();
    }
  }

};
</script>

<style lang="scss" scoped>

</style>
